<template>
  <xh-list-container
    ref="pageList"
    title="验货记录表"
    :request="request"
    @clickAdd="handleClickAdd"
    :columns="columns"
    rowKey="id"
  >
    <template v-slot="scope">
      <xh-list-item
        v-for="(item, index) in scope.data"
        :item-data="item"
        :index="index"
        :key="item.id"
        :columns="columns"
        @click="handleClickDetail(item)"
        @clickBtns="handleClickBtns"
        :buttons="[
          {
            text: '编辑',
            key: 'edit',
            color: 'primary',
          },
          {
            text: '删除',
            key: 'delete',
            color: 'error',
          },
        ]"
      />
    </template>
  </xh-list-container>
</template>

<script>
import {
  getInspectionMngList,
  deleteInspectionMng,
} from "@/api/purchase/inspectionRecords.js";
export default {
  name: "bottleInspect",
  data() {
    return {
      request: getInspectionMngList,
      columns: [
        {
          label: "验货日期",
          key: "inspectionTime",
          searchType: "daterange",
          searchOrder: 1,
        },
        {
          label: "产品名称",
          key: "productName",
          search: false,
        },
        {
          label: "柜号",
          key: "orderNum",
          search: false,
        },
      ],
    };
  },
  onShow() {
    this.$refs.pageList?._query();
  },
  methods: {
    handleClickDetail() {},
    handleClickBtns(btnKey, item, index) {
      if (btnKey === "delete") {
        this.handleDeleteItem(item, index);
      } else if (btnKey === "edit") {
        this.$nav.navigateTo(
          "/subProductionManage/inspectionRecords/addForm",
          item
        );
      }
    },
    handleClickAdd() {
      this.$nav.navigateTo("/subProductionManage/inspectionRecords/addForm");
    },
    handleDeleteItem(item) {
      const { id } = item;
      this.$modal.confirm("确定删除吗？").then(() => {
        deleteInspectionMng(id).then(() => {
          this.$modal.msgSuccess("删除成功！");
          this.$refs.pageList?._query();
        });
      });
    },
  },
};
</script>
